﻿//source http://michaelsync.net/2009/06/09/bindable-wpf-richtext-editor-with-xamlhtml-convertor
using System.Windows;
using System.Windows.Controls;
using ScrumTable.UI.View.Converter;

namespace ScrumTable.UI.View.WinTouch.UserControls.HtmlRichText.Controls
{
    /// <summary>
    /// Interaction logic for BindableRichTextbox.xaml
    /// </summary>
    public partial class RichTextHtmlBox : UserControl
    {
        public static readonly DependencyProperty TextProperty =
          DependencyProperty.Register("Text", typeof(string), typeof(RichTextHtmlBox),
          new PropertyMetadata(string.Empty));


        public static readonly DependencyProperty IsHtmlProperty =
          DependencyProperty.Register("IsHtml", typeof(bool), typeof(RichTextHtmlBox),
          new PropertyMetadata(true));

        public RichTextHtmlBox()
        {
            Loaded += OnLoaded;
        }

        void OnLoaded(object sender, RoutedEventArgs e)
        {
            Loaded -= OnLoaded;
            Resources["RemoveTags"] = new ConverterRemoveHtmlTags() {IsHtml = this.IsHtml, MaxCharCount = 100};
            
            InitializeComponent();
        }


        public bool IsHtml
        {
            get { return (bool)GetValue(IsHtmlProperty); }
            set {SetValue(IsHtmlProperty, value);}
        } 
        public string Text
        {
            get { return GetValue(TextProperty) as string; }
            set { SetValue(TextProperty, value);
            }
        } 
    }
}
